<template>
  <div>
    <van-nav-bar
      title="分类"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
   <!-- 导航 -->
      <ul class="dao">
        <li
          v-for="(item, index) in flist"
          :key="index"
          :class="{ lis: item.id == ids }"
          @click="fenll(item)"
        >
          {{ item.name }}
        </li>
      </ul>
       <!-- 列表 -->
    <p class="qweqweqw" v-if="fenglist.length == 0">加载中。。。</p>
    <div class="neilist" v-else>
      <div class="list1">
        <p>{{ currentNav.name }}</p>
        <span>{{ currentNav.front_desc }}</span>
      </div>
      <div class="list2">
        <div
          v-for="(item, index) in fenglist"
          :key="index"
          @click="xiang(item)"
        >
          <img :src="item.list_pic_url" alt="" />
          <p>{{ item.name }}</p>
          <span>￥{{ item.retail_price }}</span>
        </div>
      </div>
    </div>
    <Nav />
  </div>
</template>
<script>
import Nav from "../components/nav";
export default {
  components: {
    Nav,
  },
  data() {
    return {
    ids: "1005002",
      flist: [],
      fenglist: [], //获取分类详情
      currentNav: {},
    };
  },
  mounted() {
    this.ttt();
    this.getfan();
    this.getfan2(this.ids);
  },
  methods: {
     //跳转来后选中
    ttt() {
      console.log(this.$route.query.id);
      if (this.$route.query.id) {
        this.ids = this.$route.query.id;
      } else {
        this.ids = "1005000";
      }
    },
    onClickLeft() {
      this.$router.go(-1);
    },  // 分类导航
    getfan() {
      this.$http(
        "http://shop.bufantec.com/bufan/category/categoryNav?id=1008000",
        "get"
      ).then((res) => {
        // console.log(res);
        this.flist = res.data.navData;
      });
    },
    //分类选中
    fenll(item) {
      this.ids = item.id;
      this.getfan2(item.id);
    },
    //  获取分类详情
    getfan2(idnum) {
      this.$http(
        `http://shop.bufantec.com/bufan/goods/goodsList?categoryId=${idnum}`,
        "get"
      ).then((res) => {
        console.log(res.data);
        this.currentNav = res.data.currentNav;
        this.fenglist = res.data.data;
      });
    },
    //跳转详情页面
    xiang(item) {
      // console.log(item.id);
      this.$router.push({ path: "/xiang", query: { ss: item.id } });
    },
  },
};
</script>

<style lang="scss">
.dao {
  width: 100%;
  height: 40px;
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  li {
    // background: chartreuse;
    height: 100%;
    line-height: 40px;
    box-sizing: border-box;
  }
  .lis {
    border-bottom: 3px red solid;
  }
}
// -----
.neilist {
  width: 100%;
  .list1 {
    width: 100%;
    height: 60px;
    margin-top: 95px;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    span {
      font-size: 13px;
    }
  }
  .list2 {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 3px;
    div {
      background: #fff;
      width: 49.5%;
      //   height: 100px;
      margin-bottom: 3px;
      text-align: center;
      box-sizing: border-box;
      padding: 10px;
      img {
        width: 120px;
        height: 150px;
      }
      p {
        font-size: 14px;
      }
      span {
        color: crimson;
      }
    }
  }
}
.qweqweqw {
  width: 200px;
  height: 200px;
  background: rgb(71, 71, 71);
  color: #fff;
  text-align: center;
  line-height: 200px;
  display: inline-block;
  position: fixed;
  top: 210px;
  left: 100px;
 
}
</style>
